package com.cobra.rdd.dep

import org.apache.spark.{SparkConf, SparkContext}

object Spark01_RDD_Dep {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local").setAppName("Spark01_RDD_Dep")
    val sc = new SparkContext(conf)
    val lines = sc.textFile("datas/word.txt")
    println(lines.toDebugString)
    println("**************************")
    val words = lines.flatMap(_.split(" "))
    println(words.toDebugString)
    println("**************************")
    val wordGroup = words.groupBy(word => word)
    println(wordGroup.toDebugString)
    println("**************************")
    val wordToCount = wordGroup.map {
      case (word, list) => {
        (word, list.size)
      }
    }
    println(wordToCount.toDebugString)
    println("**************************")
    val tuples = wordToCount.collect()
    tuples.foreach(println)
    //关闭连接
    sc.stop()
  }
}
